package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.istack.internal.logging.Logger;

import service.AreaManager;
import service.AreaManagerFactory;

/**
 * Servlet implementation class SearchServlet
 */
public class SearchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	AreaManager areaManager = null;
   
    public SearchServlet() {
        super();
        areaManager = AreaManagerFactory.getInstance();
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Logger logger = Logger.getLogger(SearchServlet.class);
		String areaName = (String)request.getParameter("areaName");
		String jsonStr = "[]";
		if(!"".equals(areaName.trim())){
			jsonStr = areaManager.findFiveAreasByNameToJson(areaName);
		}
		logger.info(jsonStr);
		response.setCharacterEncoding("UTF-8");                      //解决中文乱码
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("content-type","text/html;charset=UTF-8");//解决中文乱码
		PrintWriter out = response.getWriter();
		
		out.println(jsonStr);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
